package oop.java0324.firm;

public class Firm {
    String name;
    String address;
    String telePhone;
    String scope;    //经营范围
    int numberOfEmployee;//员工数量，索引
    Employee[] employee = new Employee[10];

    public Firm(String name, String address, String telePhone, String scope) {
        this.name = name;
        this.address = address;
        this.telePhone = telePhone;
        this.scope = scope;
    }
    //查看公司信息
    public void showFirmInfo(){
        System.out.println("姓名："+name);
        System.out.println("地址："+address);
        System.out.println("联系电话："+telePhone);
        System.out.println("经营范围："+scope);
        System.out.println("公司人数："+getNumberOfEmployee());
    }

    //招聘员工
    public boolean add(Employee employee) {
        if (numberOfEmployee >= this.employee.length) {
            System.out.println("公司人员饱和了");
            return false;
        }
        this.employee[numberOfEmployee++] = employee;
        System.out.println("欢迎" + employee.name + "加入公司");
        return true;
    }

    //辞退员工(用姓名判断的话，不排除重名的可能)
    public boolean dissmissEmployee(String no) {
        for (int i = 0; i < numberOfEmployee; i++) {
            if (employee[i].no.equals(no)) {
                //从找到的员工位置到numberOfEmployee-1,数据前移一位
                for (int j = i; j < numberOfEmployee - 1; j++) {
                    employee[j] = employee[j + 1];
                }
                //最后一位设置为空
                employee[numberOfEmployee - 1] = null;
                //员工人数减一
                System.out.println("成功辞退！");
                numberOfEmployee--;
                return true;
            }
        }
        System.out.println("公司没有该员工！");
        return false;
    }
//判断员工属于公司
//    public boolean check(String no){
//        for (int i=0;i<numberOfEmployee;i++){
//            if(no.equals(employee[i].no)){
//                return true;
//            }
//        }
//        return false;
//    }
    //输出员工信息
    public void showEmployeeInfo(){
        System.out.println("员工信息：");
        for (int i =0 ;i<numberOfEmployee;i++){
            employee[i].showInfo();
        }
    }
    //获取公司总人数
    public int getNumberOfEmployee(){
        return numberOfEmployee;
    }
    //查找薪水最高的员工
    public void findTopSalary(){
        double max=employee[0].salary;
        //记录工资最高的位置
        int j =0;
        for (int i =0 ;i<numberOfEmployee;i++){
            if(employee[i].salary>max){
                max=employee[i].salary;
                j=i;
            }
        }
        System.out.println("最高工资："+max+",信息如下：");
        employee[j].showInfo();
    }
    //按照工资排序(利用bubble排序)
    public void sortBySalary(){
        for(int i=0;i<numberOfEmployee-1;i++){
            for(int j =0;j<numberOfEmployee-1-i;j++){
                if(employee[j+1].salary>employee[j].salary){
                    Employee temp = employee[j+1];
                    employee[j+1]=employee[j];
                    employee[j]=temp;
                }
            }
        }
        System.out.println("工资从高到低排序：");
        for(int i = 0;i<numberOfEmployee;i++){

            employee[i].showInfoSalary();
        }
    }

}
